package com.wwtech.epp.ui.activity.friend;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wwtech.epp.R;
import com.wwtech.epp.application.AppConfig;
import com.wwtech.epp.base.BaseActivity;
import com.wwtech.epp.entity.AllNode;
import com.wwtech.epp.ui.activity.friend.component.DaggerFrameworkComponent;
import com.wwtech.epp.ui.activity.friend.contract.FrameworkContract;
import com.wwtech.epp.ui.activity.friend.module.FrameworkModule;
import com.wwtech.epp.ui.activity.friend.presenter.FrameworkPresenter;
import com.wwtech.epp.ui.adapter.work.FrameworkAdapter;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author hzp
 * @Package com.wwtech.epp.ui.activity.friend
 * @Description: $description
 * @date 2017/10/24 20:19:32
 */

public class FrameworkActivity extends BaseActivity implements FrameworkContract.View {

    @Inject
    FrameworkPresenter mPresenter;
    @Inject
    FrameworkAdapter frameworkAdapter;
    @BindView(R.id.recycerView)
    RecyclerView recycerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_framework);
        ButterKnife.bind(this);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setTitle("组织架构");
        frameworkAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                if (getIntent().getStringExtra("flag").equals("checkPerson")) {
                    Intent intent = new Intent();
                    intent.putExtra("nodeId", frameworkAdapter.getData().get(i).getId());
                    intent.putExtra("count", frameworkAdapter.getData().get(i).getMemberCnt());
                    setResult(RESULT_OK, intent);
                    finish();
                } else {
                    Intent intent = new Intent(FrameworkActivity.this, FriendListActivity.class);
                    intent.putExtra("flag", "zuzhi");
                    intent.putExtra("total", frameworkAdapter.getData().get(i).getMemberCnt());
                    intent.putExtra("id", frameworkAdapter.getData().get(i).getId() + "");
                    intent.putExtra("name", frameworkAdapter.getData().get(i).getName());
                    startActivity(intent);
                }
            }
        });
        recycerView.setLayoutManager(new LinearLayoutManager(this));
        recycerView.setAdapter(frameworkAdapter);
    }

    @Override
    protected void initData() {
        Map<String, String> map1 = new HashMap<>();
        mPresenter.getAllNode(map1);
    }

    @Override
    protected void setupActivityComponent() {
        DaggerFrameworkComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .frameworkModule(new FrameworkModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void setPresenter(FrameworkContract.FrameworkContractPresenter presenter) {
        mPresenter = (FrameworkPresenter) presenter;
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    public void setAdapter(AllNode allNode) {
        frameworkAdapter.setNewData(allNode.getData());
    }

}